package del4;

/**
 * this is our solution for 11.4.a
 */
public class OpgA {

	/**
	 * this is the main method of OpgA
	 */
	public static void main(String[] args) {
		System.out.println("main started");

		final MyRunnable1 r1 = new MyRunnable1();
		final Thread t1 = new Thread(r1);

		final MyRunnable2 r2 = new MyRunnable2(t1);
		final Thread t2 = new Thread(r2);

		t1.start();
		t2.start();

		// Makes certain that main isn't finished before t1 is awake
		try {
			t1.join();
		} catch (InterruptedException e) {
		}

		System.out.println("main is now done!");
	}
}

/**
 * This class is home to the run method of Thread1
 */
class MyRunnable1 implements Runnable {

	@Override
	public void run() {
		System.out.println("t1 has now been made");
		System.out.println("t1 is now sleeping");
		try {
			Thread.sleep(10000);
		} catch (InterruptedException e) {
			System.out.println("t1 has been interrupted!");
		}
	}
}

/**
 * This class is home to the run method of Thread2
 */
class MyRunnable2 implements Runnable {

	private Thread t;

	public MyRunnable2(Thread t) {
		this.t = t;
	}

	public void run() {
		System.out.println("t2 has now been made");
		System.out.println("t2 has now called t1.interrupt()");
		t.interrupt();
	}
}
